home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 4_8.lha / 4_8 / 4_8b.c < prev    next >
Text File  |  1993-08-08  |  607b  |  36 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <stack.h>
  6. include <error.h>
  7.  
  8. / add a value to a stack
  9. oid push(stack *s, stacktype c)
  10.  
  11.    if (s->curtop < s->maxsize)
  12. s->mem[s->curtop++] = c;
  13.    else
  14. error("stack overflow");
  15.  
  16.  
  17. / return and remove top of stack
  18. tacktype pop(stack *s)
  19.  
  20.    if (s->curtop > 0)
  21. return s->mem[--s->curtop];
  22.  
  23.    else
  24. error("stack underflow");
  25.  
  26.  
  27. / return top of stack
  28. tacktype top(stack *s)
  29.  
  30.    if (s->curtop > 0)
  31. return s->mem[s->curtop - 1];
  32.  
  33.    else
  34. error("stack underflow");
  35.  
  36.